Meaning of the word "away goes the devil when he finds the door shut against him" in English

What does "away goes the devil when he finds the door shut against him" mean in English? Explore the meaning, pronunciation, and specific usage of this word with Lingoland.

away goes the devil when he finds the door shut against him

US /əˈweɪ ɡoʊz ðə ˈdɛvəl wɛn hi faɪndz ðə dɔːr ʃʌt əˈɡɛnst hɪm/
UK /əˈweɪ ɡəʊz ðə ˈdɛvəl wɛn hiː faɪndz ðə dɔː ʃʌt əˈɡɛnst hɪm/
"away goes the devil when he finds the door shut against him" picture

Idiom

a proverb suggesting that temptation or evil will leave if one remains firm and does not provide an opportunity for it to enter

Example:
He refused to join the corrupt scheme, believing that away goes the devil when he finds the door shut against him.
By ignoring the constant temptations, she proved that away goes the devil when he finds the door shut against him.